package cn.kgc.ssm.controller;

import cn.kgc.ssm.dto.UserPageDTO;
import cn.kgc.ssm.entity.User;
import cn.kgc.ssm.service.UserService;
import cn.kgc.ssm.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author: mosin
 * @version: v1.0  2022/10/20
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
   private UserService userService;

    @RequestMapping("all")
    public Result search(UserPageDTO userPageDTO){
        Result result = userService.search(userPageDTO);
        return  result;
    }

    // 以json格式的数据方式添加用户信息
    @RequestMapping("add")
    public Result add(@RequestBody User user){

        System.out.println(user);
        Result result = userService.add(user);
        return  result;
    }

    // 以json格式的数据方式修改用户信息
    @RequestMapping("update")
    public Result update(@RequestBody User user){
        System.out.println(user);
        Result result = userService.update(user);
        return  result;
    }


    @RequestMapping("delete")
    public Result deleteMore(String ids){
        String[] IdArray = ids.split(",");
        return  userService.deleteMore(IdArray);
    }
}
